<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<div class="portlet box green">
    <div class="portlet-title">
        <div class="caption">
            <i class="fa fa-gift"></i>医院
        </div>
    </div>
    <div class="portlet-body form">
        <form id="hospitalsForm" class="form-horizontal form-bordered" action="/hospitals/save" method="post">
            <div class="form-group">
                <label class="col-md-3 control-label">医院名称:</label>
                <div class="col-md-4">
                    <input type="text" name="hospitalName" class="form-control" value="${hospitals.hospitalName}"
                           maxlength="32"/>
                </div>
            </div>
            <div class="form-group ">
                <label class="control-label col-md-3">图片:</label>
                <div class="col-md-9">
                    <div class="fileinput fileinput-new" data-provides="fileinput">
                        <div class="fileinput-preview thumbnail" data-trigger="fileinput"
                             style="width: 200px; height: 150px;">
                            <c:if test="${not empty hospitals.imageUrl}">
                                <img src="<c:url value="/common/showImage?filePath=${hospitals.imageUrl}"></c:url>" alt=""/>
                            </c:if>
                        </div>
                        <div>
							<span class="btn default btn-file">
								<span class="fileinput-new">选择图片</span>
								<span class="fileinput-exists">编辑</span>
								<input type="file" name="imageUrl">
							</span>
                            <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput">删除</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">医院等级:</label>
                <div class="col-md-4">
                    <input type="text" name="level" class="form-control" value="${hospitals.level}" maxlength="20"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">省:</label>
                <div class="col-md-4">
                    <input type="text" name="adderssProvinceId" class="form-control"
                           value="${hospitals.adderssProvinceId}" maxlength="32"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">市:</label>
                <div class="col-md-4">
                    <input type="text" name="adderssCityId" class="form-control" value="${hospitals.adderssCityId}"
                           maxlength="32"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">地址:</label>
                <div class="col-md-4">
                    <input type="text" name="addressDetail" class="form-control" value="${hospitals.addressDetail}"
                           maxlength="65,535"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">简介:</label>
                <div class="col-md-4">
                    <div class="input-icon right">
                        <i class="fa"></i>
                        <textarea rows="5" class="form-control" name="introduction">${hospitals.introduction}</textarea>
                    </div>
                </div>
            </div>
            <div class="form-actions">
                <div class="col-md-9 col-md-offset-3">
                    <button type="button" class="btn btn-primary" onclick="saveHospital(this)">
                        <spring:message code="btn.save"></spring:message>
                    </button>
                    <button type="reset" class="btn btn-default" onclick="cancel()">
                        <spring:message code="btn.return"></spring:message>
                    </button>
                </div>
            </div>
            <input type="hidden" name="id" value="${hospitals.id}">
        </form>
    </div>
</div>
<script type="text/javascript" src="<c:url value="/static/custom/datepicker-util.js"></c:url>"></script>
<script type="text/javascript">
    $(function () {
        $('#hospitalsForm').validate();
    });

    function saveHospital(obj) {
        if ($('#hospitalsForm').valid()) {

            var formData = new FormData($('#hospitalsForm')[0]);
            $.ajax({
                type: 'post',
                url: '<c:url value="/hospitals/save"></c:url>',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (data) {
                    alert(messages[data.result]);
                    search();
                    $(".panel-search").show();
                }
            });
        }
    }
</script>